{include file="common/mainHead"/}
<div class="admin-main fadeInUp animated" ng-app="webgood" ng-controller="ctrl">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('title')}</label>
            <div class="layui-input-4">
                <input type="text" name="title" ng-model="field.title" lay-verify="required" placeholder="{:lang('pleaseEnter')}{:lang('title')}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-4">
                <input type="number" name="sort" ng-model="field.sort" lay-verify="required" placeholder="{:lang('pleaseEnter')}排序号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">起拍价</label>
            <div class="layui-input-4">
                <input type="number" name="start_price" ng-model="field.start_price" lay-verify="required" placeholder="{:lang('pleaseEnter')}起拍价" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">加价幅度</label>
            <div class="layui-input-4">
                <input type="number" name="marup_price" ng-model="field.marup_price" lay-verify="required" placeholder="{:lang('pleaseEnter')}加价幅度" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">保留价</label>
            <div class="layui-input-4">
                <input type="number" name="end_price" ng-model="field.end_price" lay-verify="required" placeholder="{:lang('pleaseEnter')}保留价" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">自由竞价</label>
            <div class="layui-input-4">
                <input type="number" name="freetime" ng-model="field.freetime" lay-verify="required" placeholder="{:lang('pleaseEnter')}自由竞价（秒）" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">限时竞价</label>
            <div class="layui-input-4">
                <input type="number" name="cuttime" ng-model="field.cuttime" lay-verify="required" placeholder="{:lang('pleaseEnter')}限时竞价（秒）" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">拍卖师</label>
            <div class="layui-input-4">
                <input type="text" name="auctineer" ng-model="field.auctineer" lay-verify="required" placeholder="{:lang('pleaseEnter')}拍卖师" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">拍卖公司</label>
            <div class="layui-input-4">
                <input type="text" name="acut_company" ng-model="field.acut_company" lay-verify="required" placeholder="{:lang('pleaseEnter')}拍卖公司" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">证书号</label>
            <div class="layui-input-4">
                <input type="text" name="code_num" ng-model="field.code_num" lay-verify="required" placeholder="{:lang('pleaseEnter')}证书号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-4">
                <input type="text" name="phone" ng-model="field.phone" lay-verify="required" placeholder="{:lang('pleaseEnter')}联系电话" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">封面图片1</label>
            <div class="layui-input-block">
                <div class="site-demo-upload">
                    <img id="cltThumb1" src="__ADMIN__/images/tong.png">
                    <div class="site-demo-upbar">
                        <input type="file" name="pic1" lay-type="images" class="layui-upload-file" id="thumb1">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">封面图片2</label>
            <div class="layui-input-block">
                <div class="site-demo-upload">
                    <img id="cltThumb2" src="__ADMIN__/images/tong.png">
                    <div class="site-demo-upbar">
                        <input type="file" name="pic2" lay-type="images" class="layui-upload-file" id="thumb2">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">封面图片3</label>
            <div class="layui-input-block">
                <div class="site-demo-upload">
                    <img id="cltThumb3" src="__ADMIN__/images/tong.png">
                    <div class="site-demo-upbar">
                        <input type="file" name="pic3" lay-type="images" class="layui-upload-file" id="thumb3">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">封面图片4</label>
            <div class="layui-input-block">
                <div class="site-demo-upload">
                    <img id="cltThumb4" src="__ADMIN__/images/tong.png">
                    <div class="site-demo-upbar">
                        <input type="file" name="pic4" lay-type="images" class="layui-upload-file" id="thumb4">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">拍品描述</label>
            <div class="layui-input-4">
                <textarea ng-model="field.good_des"  lay-verify="required" name="good_des" placeholder="{:lang('pleaseEnter')}拍品描述" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">拍卖规则</label>
            <div class="layui-input-4" id="box_rule">
                <input type="hidden" id="editType" value="0">
                <textarea name="rule" ng-model="field.rule" min="0" max="0" errormsg="出错啦" title="拍卖规则" placeholder="请输入拍卖规则"  class="rule" id="rule" ></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('WebGoods/index')}?id={{field.auct_id}}" class="layui-btn layui-btn-primary">{:lang('back')}拍品列表</a>
                <a href="{:url('WebGoods/detailGood')}?id={{field.id}}" class="layui-btn layui-btn-primary">{:lang('back')}拍品详情</a>
            </div>
        </div>

    </form>
</div>
{include file="common/mainFoot"/}
<script src="__STATIC__/js/angular.min.js"></script>
<script>/*id,auct_id title thumb1,thumb2,thumb3,thumb4,good_des freetime cuttime ,start_price,marup_price,
    end_price acut_company auctineer code_num phone*/
    var m = angular.module('webgood',[]);
    m.controller('ctrl',['$scope',function($scope) {
        $scope.field = '{$info}'!='null'?{$info}:{id:'',auct_id:'{$auct_id}',title:'',thumb1:'',thumb2:'',thumb3:'',thumb4:'',good_des:'',freetime:'',cuttime:'',start_price:'',marup_price:'',end_price:'',acut_company:'',auctineer:'',code_num:'',phone:'',rule:'',sort:''};
        layui.use(['form', 'layer','upload','laydate','layedit'], function () {
            var form = layui.form(), layer = layui.layer,upload = layui.upload,layedit = layui.layedit;
            layedit.set({
                uploadImage: {
                    url: '/index.php/admin/UpFiles/editUpload.html',
                    type: 'post'
                }
            });

            var rulecon = layedit.build("rule");
            if($scope.field.thumb1){
                cltThumb1.src = "__PUBLIC__"+ $scope.field.thumb1;
            }
            if($scope.field.thumb2){
                cltThumb2.src = "__PUBLIC__"+ $scope.field.thumb2;
            }
            if($scope.field.thumb3){
                cltThumb3.src = "__PUBLIC__"+ $scope.field.thumb3;
            }
            if($scope.field.thumb4){
                cltThumb4.src = "__PUBLIC__"+ $scope.field.thumb4;
            }
            upload({
                url: '{:url("UpFiles/upload")}',
                title: '封面图片',
                ext: 'jpg|png|gif', //那么，就只会支持这三种格式的上传。注意是用|分割。
                success: function(res, input){
                    if(input.name == 'pic1'){
                        cltThumb1.src = "__PUBLIC__"+res.url;
                        $scope.field.thumb1 = res.url;
                    }else if(input.name == 'pic2'){
                        cltThumb2.src = "__PUBLIC__"+res.url;
                        $scope.field.thumb2 = res.url;
                    }else if(input.name == 'pic3'){
                        cltThumb3.src = "__PUBLIC__"+res.url;
                        $scope.field.thumb3 = res.url;
                    }else if(input.name == 'pic4'){
                        cltThumb4.src = "__PUBLIC__"+res.url;
                        $scope.field.thumb4 = res.url;
                    }

                }
            });


            form.on('submit(submit)', function (data) {
                // 提交到方法 默认为本身
                if($scope.field.id != '')
                    data.field.id = $scope.field.id;
                data.field.thumb1 = $scope.field.thumb1;
                data.field.thumb2 = $scope.field.thumb2;
                data.field.thumb3 = $scope.field.thumb3;
                data.field.thumb4 = $scope.field.thumb4;
                data.field.auct_id = $scope.field.auct_id;
                if($('#editType').val()=='0'){
                    data.field.rule = layui.layedit.getContent(rulecon);
                }
                $.post("", data.field, function (res) {
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            })
        });
    }]);
</script>